﻿using System.Diagnostics;

namespace NetFramework.Logging.CoreLoggers
{
    public class EventLogger : FormattableLoggerBase
    {
        protected override void Log(LogItem item)
        {
            EventLog.WriteEntry(
                ApplicationContext.ApplicationName,
                FormatLog(item),
                GetEntryType(item.LogLevel), 50000);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="eventType"></param>
        /// <returns></returns>
        private EventLogEntryType GetEntryType(LogLevel eventType)
        {
            EventLogEntryType logEntryType = EventLogEntryType.Error;

            switch (eventType)
            {
                case LogLevel.Error:
                    logEntryType = EventLogEntryType.Error;
                    break;
                case LogLevel.Warn:
                    logEntryType = EventLogEntryType.Warning;
                    break;
                case LogLevel.Info:
                    logEntryType = EventLogEntryType.Information;
                    break;
            }

            return logEntryType;
        }
    }
}
